package me.andy.superappsorganizer.model;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class SAppsDatabase extends SQLiteOpenHelper {
    private static final String DEBUG_TAG = "SAppsDatabase";
    private static final int DB_VERSION = 2;
    private static final String DB_NAME = "sappsorganizer_data";
 
    public static final String TABLE_APPS_INFO = "apps_info";
    public static final String ID = "_id";
    public static final String COL_APP_TITLE = "app_title";
	public static final String COL_APP_UPDATED = "app_updated";
    public static final String COL_APP_INSTALLED = "app_installed";
    public static final String COL_WEB_UPDATED = "web_updated";
    public static final String COL_WEB_DEVELOPER = "web_developer";
    public static final String COL_WEB_URL = "web_url";
    public static final String COL_WEB_CATEGORY = "web_category";
    public static final String COL_WEB_INSTALLS = "web_installs";
    public static final String COL_WEB_CONTENT_RATING = "web_content_rating";
    public static final String COL_WEB_RATING = "web_rating";
     
    private static final String CREATE_TABLE_APPS_INFO = "create table " + TABLE_APPS_INFO
    		+ " (" + ID + " integer primary key autoincrement, "
    		+ COL_APP_TITLE + " text not null, "
    		+ COL_APP_UPDATED + " integer null, "
    		+ COL_APP_INSTALLED + " integer null, "
    		+ COL_WEB_UPDATED + " text null, "
    		+ COL_WEB_DEVELOPER + " text null, "
    		+ COL_WEB_URL + " text null, "
    		+ COL_WEB_CATEGORY + " text null, "
    		+ COL_WEB_INSTALLS + " integer null, "
    		+ COL_WEB_CONTENT_RATING + " text null, "
    		+ COL_WEB_RATING + " text null);";
     
    private static final String DB_SCHEMA = CREATE_TABLE_APPS_INFO;

    
    public SAppsDatabase(Context context) {
        super(context, DB_NAME, null, DB_VERSION); 
    }
 
    @Override
    public void onCreate(SQLiteDatabase db) {
    	db.execSQL(DB_SCHEMA);
    }
 
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.w(DEBUG_TAG, "Upgrading database. Existing contents will be lost. ["
                + oldVersion + "]->[" + newVersion + "]");
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_APPS_INFO);
        onCreate(db);
    }
}